﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IAdditionItemService))]
    public class AdditionItemService : CoreServiceBase, IAdditionItemService
    {
        [Import]
        public IAdditionItemRepository AdditionItemRepository { get; set; }

        public IQueryable<AdditionItem> AdditionItems
        {
            get { return AdditionItemRepository.Entities; }
        }




        public OperationResult Insert(Domain.ViewModels.BasicSet.AdditionItem.AdditionItemModel model)
        {
            var entity = new AdditionItem
            {
                Id = model.Id,
                Yong_SLX_No = model.Yong_SLX_No != 0 ? model.Yong_SLX_No : null,
                Fu_JXM = model.Fu_JXM,
                Fu_JFDJ = model.Fu_JFDJ,
                CreateDT = DateTime.Now,
                ReviseDT = DateTime.Now

            };
            AdditionItemRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.AdditionItem.AdditionItemModel model)
        {
            var entity = new AdditionItem
            {
                Id = model.Id,
                Yong_SLX_No = model.Yong_SLX_No != 0 ? model.Yong_SLX_No : null,
                Fu_JXM = model.Fu_JXM,
                Fu_JFDJ = model.Fu_JFDJ,
                CreateDT = DateTime.Now,

                ReviseDT = DateTime.Now
            };
            AdditionItemRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var model = AdditionItems.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;

            AdditionItemRepository.Delete(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
